/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package POJOS;

import java.beans.PropertyChangeListener;
import java.beans.PropertyChangeSupport;
import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import javax.persistence.Transient;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author jim
 */
@Entity
@Table(name = "ALBUM")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "Album.findAll", query = "SELECT a FROM Album a"),
    @NamedQuery(name = "Album.findByIdAlbum", query = "SELECT a FROM Album a WHERE a.idAlbum = :idAlbum"),
    @NamedQuery(name = "Album.findByTitle", query = "SELECT a FROM Album a WHERE a.title = :title"),
    @NamedQuery(name = "Album.findByReleaseDate", query = "SELECT a FROM Album a WHERE a.releaseDate = :releaseDate"),
    @NamedQuery(name = "Album.findByTypeAlbum", query = "SELECT a FROM Album a WHERE a.typeAlbum = :typeAlbum"),
    @NamedQuery(name = "Album.findByDiskNumber", query = "SELECT a FROM Album a WHERE a.diskNumber = :diskNumber")})
public class Album implements Serializable {
    @Transient
    private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "ID_ALBUM")
    private Integer idAlbum;
    @Basic(optional = false)
    @Column(name = "TITLE")
    private String title;
    @Basic(optional = false)
    @Column(name = "RELEASE_DATE")
    @Temporal(TemporalType.DATE)
    private Date releaseDate;
    @Basic(optional = false)
    @Column(name = "TYPE_ALBUM")
    private String typeAlbum;
    @Basic(optional = false)
    @Column(name = "DISK_NUMBER")
    private int diskNumber;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "idAlbum")
    private Collection<Song> songCollection;
    @JoinColumn(name = "ID_ARTIST", referencedColumnName = "ID_ARTIST")
    @ManyToOne
    private Artist idArtist;
    @JoinColumn(name = "ID_MUSIC_GROUP", referencedColumnName = "ID_MUSIC_GROUP")
    @ManyToOne
    private MusicGroup idMusicGroup;
    @JoinColumn(name = "ID_MUSIC_PRODUCTION_COMPANY", referencedColumnName = "ID_MUSIC_PRODUCTION_COMPANY")
    @ManyToOne(optional = false)
    private MusicProductionCompany idMusicProductionCompany;

    public Album() {
    }

    public Album(Integer idAlbum) {
        this.idAlbum = idAlbum;
    }

    public Album(Integer idAlbum, String title, Date releaseDate, String typeAlbum, int diskNumber) {
        this.idAlbum = idAlbum;
        this.title = title;
        this.releaseDate = releaseDate;
        this.typeAlbum = typeAlbum;
        this.diskNumber = diskNumber;
    }
    
    //Επιπλέον δημιουργός για αποθήκευση στη βάση
    public Album(Integer idAlbum, String title, Date releaseDate, String typeAlbum, int diskNumber, Artist idArtist, MusicGroup idMusicGroup, MusicProductionCompany idMusicProductionCompany) {
        this.idAlbum = idAlbum;
        this.title = title;
        this.releaseDate = releaseDate;
        this.typeAlbum = typeAlbum;
        this.diskNumber = diskNumber;
        this.idArtist= idArtist;
        this.idMusicGroup = idMusicGroup;
        this.idMusicProductionCompany= idMusicProductionCompany;
    }

    public Integer getIdAlbum() {
        return idAlbum;
    }

    public void setIdAlbum(Integer idAlbum) {
        Integer oldIdAlbum = this.idAlbum;
        this.idAlbum = idAlbum;
        changeSupport.firePropertyChange("idAlbum", oldIdAlbum, idAlbum);
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        String oldTitle = this.title;
        this.title = title;
        changeSupport.firePropertyChange("title", oldTitle, title);
    }

    public Date getReleaseDate() {
        return releaseDate;
    }

    public void setReleaseDate(Date releaseDate) {
        Date oldReleaseDate = this.releaseDate;
        this.releaseDate = releaseDate;
        changeSupport.firePropertyChange("releaseDate", oldReleaseDate, releaseDate);
    }

    public String getTypeAlbum() {
        return typeAlbum;
    }

    public void setTypeAlbum(String typeAlbum) {
        String oldTypeAlbum = this.typeAlbum;
        this.typeAlbum = typeAlbum;
        changeSupport.firePropertyChange("typeAlbum", oldTypeAlbum, typeAlbum);
    }

    public int getDiskNumber() {
        return diskNumber;
    }

    public void setDiskNumber(int diskNumber) {
        int oldDiskNumber = this.diskNumber;
        this.diskNumber = diskNumber;
        changeSupport.firePropertyChange("diskNumber", oldDiskNumber, diskNumber);
    }

    @XmlTransient
    public Collection<Song> getSongCollection() {
        return songCollection;
    }

    public void setSongCollection(Collection<Song> songCollection) {
        this.songCollection = songCollection;
    }

    public Artist getIdArtist() {
        return idArtist;
    }

    public void setIdArtist(Artist idArtist) {
        Artist oldIdArtist = this.idArtist;
        this.idArtist = idArtist;
        changeSupport.firePropertyChange("idArtist", oldIdArtist, idArtist);
    }

    public MusicGroup getIdMusicGroup() {
        return idMusicGroup;
    }

    public void setIdMusicGroup(MusicGroup idMusicGroup) {
        MusicGroup oldIdMusicGroup = this.idMusicGroup;
        this.idMusicGroup = idMusicGroup;
        changeSupport.firePropertyChange("idMusicGroup", oldIdMusicGroup, idMusicGroup);
    }

    public MusicProductionCompany getIdMusicProductionCompany() {
        return idMusicProductionCompany;
    }

    public void setIdMusicProductionCompany(MusicProductionCompany idMusicProductionCompany) {
        MusicProductionCompany oldIdMusicProductionCompany = this.idMusicProductionCompany;
        this.idMusicProductionCompany = idMusicProductionCompany;
        changeSupport.firePropertyChange("idMusicProductionCompany", oldIdMusicProductionCompany, idMusicProductionCompany);
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (idAlbum != null ? idAlbum.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Album)) {
            return false;
        }
        Album other = (Album) object;
        if ((this.idAlbum == null && other.idAlbum != null) || (this.idAlbum != null && !this.idAlbum.equals(other.idAlbum))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "POJOS.Album[ idAlbum=" + idAlbum + " ]";
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        changeSupport.removePropertyChangeListener(listener);
    }
    
}
